<?php
//	pr($_SESSION);
//   pr($uid);
$usertype = $_SESSION['Group'][0]['name'];
?>

<div id="taskdetails">
<header>
    <ul class="action-buttons clearfix fr">
        <li><a href="documentation/index.html" class="button button-gray no-text help" rel="#overlay">Help<span class="help"></span></a></li>
    </ul>
    <h2>Detail View</h2>
</header>

<section class="container_6 clearfix">
<section style="width:49%; float:left; padding:0px 0px 0px 5px;">
<fieldset>
    <legend><?php echo $jadmindetail[0]['Job']['title']?></legend>
        <br />
            <!--<p>Ceated on : <?php echo $jadmindetail[0]['Job']['created']?></p>
            <p>Last Modified : <?php echo $jadmindetail[0]['Job']['modified']?></p>-->
            <p><b>Start Date : </b><?php echo $jadmindetail[0]['Job']['sdate']?></p>
            <p><b>End Date : </b><?php echo $jadmindetail[0]['Job']['edate']?></p>
            <p><b>Description :</b></p>
            <p><?php echo nl2br($jadmindetail[0]['Job']['description']) ?></p>
            <p><b>Special Instructions :</b></p>
            <p><?php echo nl2br($jadmindetail[0]['Job']['hiddendetails']) ?></p>

                <div class="span-4 last">
                    <?php
                    //echo pr($jadmindetail);
                    $hasVolunteer = $jadmindetail[0]['Job']['hasvolunteer'];
                    //echo $hasVolunteer;
                    
                    echo $form->create('Job', array('action' => 'addvol/' . $jadmindetail[0]['Job']['id']));
                    echo $form->input('User.id', array('type'=>'hidden', 'value' => $uid));
                    echo $form->input('Job.id', array('id' => 'jid', 'type' => 'hidden', 'value' => $jadmindetail[0]['Job']['id']));

                    if($hasVolunteer == 0)
                    {
                         echo $form->button('<span class="accept"></span>Volunteer', array('class' => 'button button-gray'));
                    }
                    else
                    {
                        if(isset($jadmindetail[0]['User'][0]['id']))
                        {
                            if($jadmindetail[0]['User'][0]['id'] == $uid)
                            {
                            ?>
                                <?php
                                    //echo $form->create('Job', array('action' => 'delvol/' . $jdetail[0]['Job']['id']));
                                    echo '<p><b>Current Volunteer: </b></p>';
                                    echo $this->Html->link($jadmindetail[0]['User'][0]['fname'] . ' ' . $jadmindetail[0]['User'][0]['lname'], '/users/uprofile/'. $jadmindetail[0]['User'][0]['id']);
                                    echo '<br /><br />';
                                    echo $form->button('<span class="cancel"></span>Unvolunteer', array('class' => 'button button-gray', 'onclick' => 'location.href=\'' . $this->Html->url('/jobs/delvol/'. $jadmindetail[0]['Job']['id']) . '\'' , 'type' => 'button'));
                                   // echo $jdetail[0]['Job']['id'];
                            }
                            else
                            {
                                //echo $form->button($jadmindetail[0]['User'][0]['fname'], array('onclick' => 'location.href=\'' . $this->Html->url('/users/uprofile/'. $jadmindetail[0]['User'][0]['id']) . '\'' , 'type' => 'button', 'class' => 'button'));
                                echo '<p><b>Current Volunteer: </b></p>';
                                if($usertype == 'Admin')
                                {
                                  echo $this->Html->link($jadmindetail[0]['User'][0]['fname'] . ' ' . $jadmindetail[0]['User'][0]['lname'], '/users/uprofile/'. $jadmindetail[0]['User'][0]['id']);  
                                }
                                else
                                {
                                  echo $this->Html->link($jadmindetail[0]['User'][0]['fname'] . ' ' . $jadmindetail[0]['User'][0]['lname'], '/users/sprofile/'. $jadmindetail[0]['User'][0]['id']);  
                                }
                                
                                echo '<br /><br />';
                                echo $form->button('<span class="cancel"></span>Unvolunteer ' . $jadmindetail[0]['User'][0]['fname'], array('class' => 'button button-gray', 'onclick' => 'if(confirm(\'Are you sure you want to unassign this user from the task?\')) location.href=\'' . $this->Html->url('/jobs/unvol/'. $jadmindetail[0]['Job']['id'] . '/' . $jadmindetail[0]['User'][0]['id']) . '\'' , 'type' => 'button'));
                                //echo $form->end();
                            }
                        }
                    }
                    echo '<br /><br />';

                    echo $form->button('<span class="page_white_edit"></span>Edit', array('class' => 'button button-gray', 'onclick' => 'location.href=\'' . $this->Html->url('/jobs/jedit/'.$jadmindetail[0]['Job']['id']) . '\'' , 'type' => 'button'));
                    echo $form->end();    
                    ?>
                </div>
</fieldset>
</section>

<?php if($usertype == 'Admin')
        { 
?>
<section style="width:49%; float:right; padding:0px 5px 0px 0px;">
<fieldset>
    <legend>Volunteers</legend>
    <h4>This is a list of all active volunteers.</h4>
    <p><b>To add a volunteer to this task:</b></p>
    <ul>
        <li>Select the volunteers name from the list.</li>
        <li>Use the "Assign Volunteer" option to assign the volunteer to the task.</li>
    </ul>
    <br />
    <select size="5" id="SelectUserList">
    
        <?php
            foreach($user as $users)
            {
                echo '<option value="'. $users['User']['id'] . '">' . $users['User']['fname'] . ' ' . $users['User']['lname'] . ' ('. $users['User']['email_address'] . ')</option>';
            }
        ?>
    </select>
    <br />
    <br />
    <?php echo $form->button('<span class="accept"></span>Assign Volunteer', array('class' => 'button button-gray', 'onClick' => 'assignvol(\''.$jadmindetail[0]['Job']['id'].'\');', 'type' => 'button', 'id' => 'AssignVol')); ?>
    <?php echo $this->Form->input('idBox', array('label' => '', 'id' => 'idBox', 'value' => $jadmindetail[0]['Job']['id'], 'type' => 'hidden')); ?>
</fieldset>
</section>
</section>
<?php
        }
?>
</div>
<script type="text/javascript">
$(function() {


$('#SelectUserList').click(function() {
    //var id = $("#SelectUserList").val();
    //alert(id);
});

$('#AssignVol').click(function() {
    var id = $("#SelectUserList").val();
    var text = $("#SelectUserList option:selected").text();
    var jid = $("#idBox").val();
    
    if (id == null) {
        alert("Please select a Volunteer from the list.");
    }
    else {
        //$("#idBox").val(id);
      if(confirm("Are you sure you want to assign " + text + " to this task?")) {
        //$(window).load('<?php echo $this->Html->url('/jobs/assignvol/');?>' + id + '/' + jid);
        window.location.href = '<?php echo $this->Html->url('/jobs/assignvol/');?>' + id + '/' + jid;
      }
    }
    
});


});


</script>

